package simtester.test

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware

class Utils implements ApplicationContextAware {
    
    /*static def messageSource
    
    static boolean hasErrorMsg(def obj, String ... expectedErrorsArray) {
        def expectedErrors = expectedErrorsArray as Set
        def actualErrors = obj.errors.allErrors
        if (expectedErrors.size() != actualErrors.size()) {
            return false
        }
        
        for (int i = 0; i < actualErrors.size(); i++) {
            if (! expectedErrors.contains(messageSource.getMessage(actualErrors[i], null))) {
                return false
            }
        }
        
        return true
    }*/
    
    static void dropCollections(def db) {
        db.getCollectionNames().each {
            if ( !(it =~ /system\./) ) {
                db.getCollection(it).drop()
            }
        }
    }
    
    @Override
    public void setApplicationContext(ApplicationContext appContext) throws BeansException {
        messageSource = appContext.getBean('messageSource')
    }

}
